<?php

namespace app\model;

use think\Model;

class CustomerJieduan extends Model
{

    protected $connection = 'mysql';

    protected $pk = 'id';

    protected $name = 'customer_jieduan';

    public static function datainitial()
    {
        $weid = weid();
        $complete = 0;
        $data = array('初步接触', '意向客户', '报价客户', '搁置客户', '成交');
        foreach ($data as $key => $vo) {
            if ($vo == "成交") {
                $complete = 1;
            } else {
                $complete = 0;
            }
            $updata[$key] = [
                'weid' => $weid,
                'title' => $vo,
                'create_time' => time(),
                'update_time' => time(),
                'complete' => $complete,
                'sort' => $key + 1,
                'status' => 1
            ];
        }
        $mod = new self;
        $mod->saveAll($updata);
    }

    public static function get_name($id)
    {
        $weid = weid();
        $list = self::field('id,title')->where(['weid' => $weid])
            ->select()->toArray();

        foreach ($list as $k => $v) {
            $data[$v['id']] = $v;
        }

        if (!isset($data[$id]['title'])) {
            return null;
        }
        return $data[$id]['title'];
    }

    public static function getarray()
    {
        $data = self::field('id,title')->where(['weid' => weid()])->order('sort asc')->select()->toArray();
        $datalist = [];
        foreach ($data as $vo) {
            $datalist[$vo['id']] = $vo['title'];
        }
        return $datalist;
    }
}
